package com.ygg.controller.api;

import com.ygg.model.user.Patient;
import com.ygg.result.Result;
import com.ygg.service.PatientService;
import com.ygg.utils.AuthContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "就诊人接口")
@RestController
@RequestMapping("/api/user/patient")
public class PatientController {

    @Resource
    private PatientService patientService;


    @GetMapping("/getAll")
    public Result getAll(HttpServletRequest request) {
        Long userId = AuthContextHolder.getUserId(request);
        List<Patient> PatientAll = patientService.findAllUserId(userId);
        return Result.ok(PatientAll);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        Patient patientId = patientService.getPatientId(id);
        return Result.ok(patientId);
    }

    @PostMapping
    public Result add(@RequestBody Patient patient, HttpServletRequest request) {
        patient.setUserId(AuthContextHolder.getUserId(request));
        patientService.addPatient(patient);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        patientService.deleteById(id);
        return Result.ok();
    }

    @PutMapping
    public Result updateById(@RequestBody Patient patient) {
        patientService.updatePatientById(patient);
        return Result.ok();
    }

    @ApiOperation(value = "获取就诊人")
    @GetMapping("inner/get/{id}")
    public Patient getPatientOrder(
            @ApiParam(name = "id", value = "就诊人id", required = true)
            @PathVariable("id") Long id) {
        return patientService.getPatientOrder(id);
    }


}
